package com.sfang.common.util.collection;

import java.util.ArrayList;
import java.util.List;

public class ListUtil {
    public static <T> List<List<T>> split(List<T> sourceList, Integer splitSize) {
        List<List<T>> rlt = new ArrayList<>();

        for (int i = 0; i * splitSize < sourceList.size(); i++) {
            int endIndex = (i + 1) * splitSize;

            if (endIndex > sourceList.size())
                endIndex = sourceList.size();

            List<T> item = sourceList.subList(i * splitSize, endIndex);
            rlt.add(item);
        }

        return rlt;
    }
}
